/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.isd.venta.vista;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.isd.facturacion.vista.ProductoPendiente;
import com.isd.inventario.vista.ItemStock;


/**
 *
 * @author ctrosch
 */
@Entity
@Table(name = "VT_ESTADISTICA")
@IdClass(EstadisticaPK.class)
public class Estadistica implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "VTRMVH_NROCTA", nullable = false, length = 13)
    private String nrocta;

    @Id
    @Column(name = "VTRMVI_TIPPRO", length = 6)
    private String tippro;

    @Id
    @Column(name = "VTRMVI_ARTCOD", length = 30)
    private String artcod;
    
    @Column(name = "STMPDH_DESCRP", length = 80)
    private String descrp;

    @Column(name = "STMPDH_INDCOD", length = 30)
    private String indcod;

//    @JoinColumns({
//    @JoinColumn(name = "VTRMVI_TIPPRO", referencedColumnName = "STMPDH_TIPPRO", nullable = false, insertable=false, updatable=false),
//    @JoinColumn(name = "VTRMVI_ARTCOD", referencedColumnName = "STMPDH_ARTCOD", nullable = false, insertable=false, updatable=false)
//    })
//    @ManyToOne(fetch=FetchType.LAZY)
//    private StockProductos stock;


    @OneToOne(fetch=FetchType.LAZY)
    @JoinColumns({
        @JoinColumn(name = "VTRMVI_TIPPRO", referencedColumnName = "TIPPRO", nullable = false, insertable=false, updatable=false),
        @JoinColumn(name = "VTRMVI_ARTCOD", referencedColumnName = "ARTCOD", nullable = false, insertable=false, updatable=false),
        @JoinColumn(name = "VTRMVH_NROCTA", referencedColumnName = "NROCTA", nullable = false, insertable=false, updatable=false)
    })
    private ProductoPendiente pendiente;

    @Column(name = "CANTIDAD", precision = 0, scale = 10)
    private BigDecimal cantid;
    
    @Column(name = "USR_STMPDH_IMGCHI")
    private String imgchi;
    
    @Column(name = "USR_STMPDH_IMGGRA")
    private String imggra;

    @Column(name = "USR_STMPDH_PNUEVO")
    private Character pnuevo;

    @Column(name = "USR_STMPDH_PRDPED", length =1)
    private String productoApedido;

    @Column(name = "STMPDH_STKMIN", precision = 2, scale = 7)
    private BigDecimal stockMinimo;

    @Column(name = "NOA", precision = 2, scale = 7)
    private BigDecimal noa;
    @Column(name = "NEA", precision = 2, scale = 7)
    private BigDecimal nea;
    @Column(name = "BUE", precision = 2, scale = 7)
    private BigDecimal bue;
    @Column(name = "CUY", precision = 2, scale = 7)
    private BigDecimal cuy;
    
    @Transient
    private String codigo;

    @Transient
    private boolean seleccionado;

    @Transient
    private List<ItemStock> stock;
    
    @Transient
    private BigDecimal stockTotal;

    public Estadistica() {

    }

    public String getArtcod() {
        return artcod;
    }

    public void setArtcod(String artcod) {
        this.artcod = artcod;
    }

    public BigDecimal getCantid() {
        return cantid;
    }

    public void setCantid(BigDecimal cantid) {
        this.cantid = cantid;
    }

    public String getNrocta() {
        return nrocta;
    }

    public void setNrocta(String nrocta) {
        this.nrocta = nrocta;
    }

    public String getTippro() {
        return tippro;
    }

    public void setTippro(String tippro) {
        this.tippro = tippro;
    }

    public String getCodigo() {
        return tippro.trim()+artcod.trim();
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public ProductoPendiente getPendiente() {
        return pendiente;
    }

    public void setPendiente(ProductoPendiente pendiente) {
        this.pendiente = pendiente;
    }


    public String getDescrp() {
        return descrp;
    }

    public void setDescrp(String descrp) {
        this.descrp = descrp;
    }

    public String getImgchi() {
        return imgchi;
    }

    public void setImgchi(String imgchi) {
        this.imgchi = imgchi;
    }

    public String getImggra() {
        return imggra;
    }

    public void setImggra(String imggra) {
        this.imggra = imggra;
    }

    public String getIndcod() {
        return indcod;
    }

    public void setIndcod(String indcod) {
        this.indcod = indcod;
    }

    public Character getPnuevo() {
        return pnuevo;
    }

    public void setPnuevo(Character pnuevo) {
        this.pnuevo = pnuevo;
    }

    public String getProductoApedido() {
        return productoApedido;
    }

    public void setProductoApedido(String productoApedido) {
        this.productoApedido = productoApedido;
    }

    public BigDecimal getStockMinimo() {
        return stockMinimo;
    }

    public void setStockMinimo(BigDecimal stockMinimo) {
        this.stockMinimo = stockMinimo;
    }

    public boolean isSeleccionado() {
        return seleccionado;
    }

    public void setSeleccionado(boolean seleccionado) {
        this.seleccionado = seleccionado;
    }

    public List<ItemStock> getStock() {

        if(stock==null){
            stock = new ArrayList<ItemStock>();
            if(stock!=null){
                stock.add(new ItemStock("NOA", noa));
                stock.add(new ItemStock("NEA", nea));
                stock.add(new ItemStock("BUE", bue));
                stock.add(new ItemStock("CUY", cuy));
            }else{
                stock.add(new ItemStock("NOA", BigDecimal.ZERO));
                stock.add(new ItemStock("NEA", BigDecimal.ZERO));
                stock.add(new ItemStock("BUE", BigDecimal.ZERO));
                stock.add(new ItemStock("CUY", BigDecimal.ZERO));
            }
        }
        return stock;
    }

    public void setStock(List<ItemStock> stock) {
        this.stock = stock;
    }

    public BigDecimal getStockTotal() {

        stockTotal = BigDecimal.ZERO;
        stockTotal = stockTotal.add(noa.add(nea.add(bue.add(cuy))));
        return stockTotal;
    }

    public void setStockTotal(BigDecimal stockTotal) {
        this.stockTotal = stockTotal;
    }


    public BigDecimal getBue() {
        return bue;
    }

    public void setBue(BigDecimal bue) {
        this.bue = bue;
    }

    public BigDecimal getCuy() {
        return cuy;
    }

    public void setCuy(BigDecimal cuy) {
        this.cuy = cuy;
    }

    public BigDecimal getNea() {
        return nea;
    }

    public void setNea(BigDecimal nea) {
        this.nea = nea;
    }

    public BigDecimal getNoa() {
        return noa;
    }

    public void setNoa(BigDecimal noa) {
        this.noa = noa;
    }

    
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Estadistica other = (Estadistica) obj;
        if ((this.nrocta == null) ? (other.nrocta != null) : !this.nrocta.equals(other.nrocta)) {
            return false;
        }
        if ((this.tippro == null) ? (other.tippro != null) : !this.tippro.equals(other.tippro)) {
            return false;
        }
        if ((this.artcod == null) ? (other.artcod != null) : !this.artcod.equals(other.artcod)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 73 * hash + (this.nrocta != null ? this.nrocta.hashCode() : 0);
        hash = 73 * hash + (this.tippro != null ? this.tippro.hashCode() : 0);
        hash = 73 * hash + (this.artcod != null ? this.artcod.hashCode() : 0);
        return hash;
    }


}
